/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package specifications;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedHashMap;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Tag;

/**
 *
 * @author Jason
 */

public class Specifications implements YamlObject<Specifications> {
    private LinkedHashMap<String, LinkedHashMap<String, Parameter>> specifications;
    
    public static final Tag TAG = new Tag("!FSTS");
   
    //top level
    public static final String SOURCE = "Source";
    public static final String TARGET = "Target";
    public static final String PRODUCTION = "Production";
    public static final String ENVIRONMENT = "Environment";
    public static final String RELATIONSHIPS = "Relationships";
    //source
    public static final String TEXTUAL_CHARACTERISTICS = "textual characteristics";
    public static final String SPECIALIZED_LANGUAGE = "specialized language";
    public static final String VOLUME = "volume";
    public static final String COMPLEXITY = "complexity";
    public static final String ORIGIN = "origin";
    //taget
    public static final String TARGET_LANGUAGE = "target language";
    public static final String AUDIENCE = "audience";
    public static final String PURPOSE = "purpose";
    public static final String CONTENT_CORRESPONDENCE = "content correspondence";
    public static final String REGISTER = "register";
    public static final String FILE_FORMAT = "file format";
    public static final String STYLE = "style";
    public static final String LAYOUT = "layout";
    //production
    public static final String TYPICAL_TASKS = "typical tasks";
    public static final String ADDITIONAL_TASKS = "additional tasks";
    //environment
    public static final String TECHNOLOGY = "technology";
    public static final String REFERENCE_MATERIALS = "reference materials";
    public static final String WORKPLACE_REQUIREMENTS = "workplace requirements";
    //relationships
    public static final String PERMISSIONS = "permissions";
    public static final String SUBMISSIONS = "submissions";
    public static final String EXPECTATIONS = "expectations";
    
    public Specifications(){
        specifications = new LinkedHashMap(4);
        specifications.put(SOURCE, new LinkedHashMap<String, Parameter>(5));
        specifications.put(TARGET, new LinkedHashMap<String, Parameter>(7));
        specifications.put(PRODUCTION, new LinkedHashMap<String, Parameter>(2));
        specifications.put(ENVIRONMENT, new LinkedHashMap<String, Parameter>(3));
        specifications.put(RELATIONSHIPS, new LinkedHashMap<String, Parameter>(3));
    }
            
    @Override
    public void dump(String filename) throws IOException {
        //Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        Yaml yaml = new Storage().yaml;
        FileWriter writer = new FileWriter(filename);
        writer.write(yaml.dumpAs(this, TAG, DumperOptions.FlowStyle.BLOCK));
        writer.close();
    }

    @Override
    public Specifications load(String filename) throws IOException {
        //Yaml yaml = new Yaml(CONSTRUCTOR, REPRESENTER);
        Storage st = new Storage();
        //FileReader reader = new FileReader(filename);
        //Specifications param = yaml.loadAs(reader, Specifications.class);
        Specifications param = st.load(new File(filename));
        //reader.close();
        return param;
    }


    public Parameter getParameter(String name, String category){
        return getSpecifications().get(category).get(name);
    }
    
    public void setParameter(Parameter param, String name, String category){
        getSpecifications().get(category).put(name, param);
    }
    
    public LinkedHashMap<String, Parameter> getCategory(String name){
        return getSpecifications().get(name);
    }
    
    public void setCategory(LinkedHashMap<String, Parameter> cat, String name){
        getSpecifications().put(name, cat);
    }

    /**
     * @return the specifications
     */
    public LinkedHashMap<String, LinkedHashMap<String, Parameter>> getSpecifications() {
        return specifications;
    }

    /**
     * @param specifications the specifications to set
     */
    public void setSpecifications(LinkedHashMap<String, LinkedHashMap<String, Parameter>> specifications) {
        this.specifications = specifications;
    }
}
